from django.db import models
from db.abstract_model import AbstractModel


class ImgTypeManager(models.Manager):
    # 获取所有类型
    def get_all(self):
        try:
            return self.all()
        except:
            pass


class ImgType(AbstractModel):
    type = models.CharField(max_length=20, verbose_name="图片类型")

    objects = ImgTypeManager()

    def __str__(self):
        return self.type

    class Meta:
        verbose_name_plural = "图片类型"
        verbose_name = "图片类型"


class ImgManager(models.Manager):
    pass


class Img(AbstractModel):
    type = models.ForeignKey(ImgType, verbose_name="图片类型")
    img = models.ImageField(upload_to="images/about_us", verbose_name="图片")

    objects = ImgManager()

    class Meta:
        verbose_name_plural = "图片"
        verbose_name = "图片"
